<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>登录</title>

    <script type="text/javascript" th:src="@{/bootstrap-3.3.7-dist/js/bootstrap.js}"></script>

    <script type="text/javascript" th:src="@{/bootstrap-3.3.7-dist/css/bootstrap.css}"></script>

    <script type="text/javascript" th:src="@{/js/jquery-1.12.4.min.js}"></script>

    <script type="text/javascript" th:src="@{/js/jquery.md5.js}"></script>


</head>
<body>



    <form id="signupFrom" method="post">

        <h2 style="text-align:center" >用户登录</h2>

        <div class="form-group">
            <label for="phone" >请输入手机号</label>
            <input type="phone" class="form-control" id="phone" placeholder="Phone" required="true">
        </div>

        <div class="form-group">
            <label for="password">请输入密码</label>
            <input type="password" class="form-control" id="password" placeholder="Password" required="true">
        </div>

        <div> </div>

        <button type="reset" class="btn btn-default">重置</button>

        <button type="button" class="btn btn-default" onclick="doLogin()">登录</button>

    </form>

    <script>

        function doLogin(){

            var inputPass = $("#password").val();

            var salt = "1a2b3c4d";   //应该写在common的js文件中

            var str = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);

            var password = $.md5(str);

            $.ajax({
                url:"/login/do_login",
                type:"POST",
                data:{
                    phone:$("#phone").val(),
                    password:password
                },
                dataType:  'json',
                success:function (data) {

                    if(data.code == 0){
                        alert("登录成功")
                        window.location.href = "/goods/to_list"
                    }
                    console.log(data)


                },
                error:function (data) {

                    console.log(data)

                }
            })

        }





    </script>







</body>
</html>